package org.lex.swing.fontchooser.advanced;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

public class AdvanvedFontChooserDialog extends JDialog {
	private JPanel pane = null;
	private AdvancedFontChooserPane advancedFontChooserPane = null;
	private JPanel buttonsPane = null;
	private JButton okButton = null;
	private JButton cancelButton = null;

	public AdvanvedFontChooserDialog(Window parent) {
		super(parent);
		initialize();
	}

	private void initialize() {
		this.setModal(true);
		this.setSize(300, 200);
		this.setTitle("Font");
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.setContentPane(getPane());
	}

	private JPanel getPane() {
		if (pane == null) {
			pane = new JPanel();
			pane.setLayout(new BorderLayout());
			pane.add(getFontChooserPane(), BorderLayout.CENTER);
			pane.add(getButtonsPane(), BorderLayout.SOUTH);
		}
		return pane;
	}

	private AdvancedFontChooserPane getFontChooserPane() {
		if (advancedFontChooserPane == null) {
			advancedFontChooserPane = new AdvancedFontChooserPane();
		}
		return advancedFontChooserPane;
	}

	private JPanel getButtonsPane() {
		if (buttonsPane == null) {
			FlowLayout flowLayout = new FlowLayout();
			flowLayout.setAlignment(FlowLayout.RIGHT);
			buttonsPane = new JPanel();
			buttonsPane.setLayout(flowLayout);
			buttonsPane.add(getOkButton(), null);
			buttonsPane.add(getCancelButton(), null);
		}
		return buttonsPane;
	}

	private JButton getOkButton() {
		if (okButton == null) {
			okButton = new JButton();
			okButton.setText("OK");
			okButton.setMnemonic(KeyEvent.VK_O);
		}
		return okButton;
	}

	private JButton getCancelButton() {
		if (cancelButton == null) {
			cancelButton = new JButton();
			cancelButton.setText("Cancel");
			cancelButton.setMnemonic(KeyEvent.VK_C);
		}
		return cancelButton;
	}

}
